import {object2Url} from "@/utils/trans";
import request from "@/utils/request";
import {getToken} from "@/utils/token-util";
import axios from "axios";

/**
  * 获取md5加密加盐参数
  */
export async function getSalt() {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
  };
  let url = `/auth/cert/salt${object2Url(us)}`
/*  //修改 start
  //token 白名单
  let token = getToken()
  let config = {
    headers: {
      'Authorization': token
    }
  }
  //, config 白名单
  //修改end*/
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取公钥（加密）
 * @param data
 * @returns {Promise<*>}
 */
export async function getPk(){
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
  };
  let url = `/auth/cert/pub${object2Url(us)}`
  const res = await request.get(url,us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
